//车辆银行卡管理

interface ICarBankCardManagentDetailViewModel {
    /**
     * 银行卡号
     */
    bankCode: string;
    /**
     * 开户行
     */
    bankName: string;
    /**
     * 持卡人
     */
    holder: string;
    /**
     * 开户银行启用禁用
     */
    bankDis:boolean;
}

interface ICarBankCardManagentViewModel extends IBaseViewModel<ICarBankCardManagentQueryTerms> {
    /**
     * ui-grid控制
     */
    gridOptions: uiGrid.IGridOptionsOf<BankListItemResponse>;
    /**
     * 添加视图
     */
    detail: ICarBankCardManagentDetailViewModel;
    /**
     * 删除银行卡
     */
    deleteBankCard: (id: string) => void;
    /**
     * 获取银行开户行名称
     */
    getBankName: (bankCard: string) => void;
    /**
     * 列表高
     */
    heightA:number;
}

interface ICarBankCardManagentQueryTerms {

}

class CarBankCardManagentController extends ListController<ICarBankCardManagentViewModel, ICarBankCardManagentQueryTerms> {
    gridApi: uiGrid.IGridApiOf<BankListItemResponse>;
    carId: string;

    constructor($scope: ICarBankCardManagentViewModel, private carService:ICarService, private $location: ng.ILocationService, private $ngBootbox: BootboxService) {
        super($scope);
        this.init();
    }

    init(): void {
        super.init();

        this.carId = JSON.parse(window.localStorage.getItem("car").toString()).carId;
       

        this.$scope.queryTerms = {
        };

        this.$scope.gridOptions = {
            enableSorting: false,
            useExternalPagination: true,
            useExternalSorting: true,
            enableColumnResizing: true,
            paginationPageSizes: [10, 20, 30],
            columnDefs: [
                { displayName: "开户银行", field: 'bank', enableColumnMenu: false },
                { displayName: "银行卡号", field: 'cardNumber', minWidth: 300, enableColumnMenu: false },
                { displayName: "持卡人姓名", field: 'holder', enableColumnMenu: false }
            ],
            onRegisterApi: (gridApi) => {
                this.gridApi = gridApi;
                gridApi.pagination.on.paginationChanged(this.$scope, this.paginationChanged);
            }
        }
        this.query();
    }

    loadData(queryTerms: ICarBankCardManagentQueryTerms, skip: number, count: number): void {
        this.carService.getDetail(this.carId).then((res)=>{
            this.$scope.gridOptions.data = res.data.bankList;
            this.$scope.heightA = (this.$scope.gridOptions.data.length * 39)+95;

            if(skip ==0 ){
                this.$scope.gridOptions.paginationCurrentPage = 1;
            }
            this.$scope.querying = false;
        },error =>{
            this.$scope.querying = false;
        });
    }

}

angular.module("tms").controller("carBankCardManagentController", ["$scope", "carService", "$location", "$ngBootbox", CarBankCardManagentController]);